package com.ohuang.util_a.task.rxtask;


import com.ohuang.util_a.task.FairRestartTask;
import com.ohuang.util_a.task.OnceTaskCallBack;

/**
 * 失败重试任务
 */
public class RxFairRestartTask extends FairRestartTask {

    RxTask<Object> rxTask;

    public RxFairRestartTask(int maxCount, RxTask<Object> task) {
        super(maxCount);
        this.rxTask = task;
    }

    @Override
    public void setStop(boolean stop) {
        super.setStop(stop);
        rxTask.setStop(stop);
    }

    @Override
    public void runTask(FairRestartTaskCallBack fairRestartTaskCallBack) {

        rxTask.setmReturnCallBack(new RXTaskCallBack<Object>() {
            @Override
            public void onSuccess(Object o) {
                fairRestartTaskCallBack.onSuccess();
            }

            @Override
            public void onFair() {
                fairRestartTaskCallBack.onFair();
            }
        });
        rxTask.run(new OnceTaskCallBack() {
            @Override
            public void onCall() {
                rxTask.setStop(true);
            }
        });
    }
}
